﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using WPF_DbCenter.CommonMethod;
using WPF_DbCenter.Utility;
using WPF_DbCenter.BaseUI;

namespace WPF_DbCenter.DynaControls
{
    /// <summary>
    /// Interaction logic for DbOpenedHistory.xaml
    /// </summary>
    public partial class DbOpenedHistory : BaseFadeDialog
    {
        public delegate void Del_AfterSelectedValue(string a);
        public Del_AfterSelectedValue AfterSelectedValue = null;

        public DbOpenedHistory()
        {
            InitializeComponent();

            WindowStartupLocation = WindowStartupLocation.CenterScreen;

            dbHistoryWin.KeyDown += new KeyEventHandler(dbHistoryWin_KeyDown);
            dbHistoryWin.MouseDoubleClick += new MouseButtonEventHandler(dbHistoryWin_MouseDoubleClick);
            dbHistoryWin.Items.Clear();
            List<string> list=SerializeClass.GetHistoryList();
            if (list != null)
            {
                foreach (string item in list)
                {
                    dbHistoryWin.Items.Add(item);
                }
            }

        }

        void dbHistoryWin_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
                DoSelect();
        }

        void dbHistoryWin_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                DoSelect();
            }

        }

        private void DoSelect()
        {
            string result = string.Empty;

            if (this.dbHistoryWin.SelectedItem != null)
            {
                result = this.dbHistoryWin.SelectedItem.ToString();
                if (AfterSelectedValue != null)
                {
                    AfterSelectedValue(result);

                }
                Close();
            }
        }
    }
}
